package home.game.client.display.panels;

import home.game.client.controllers.Application;
import home.game.entity.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

/**
 */
public class TopScorePanel {
    private JDialog dialog;

    public void showDialog() {
        dialog = new JDialog();
        dialog.setLayout(new GridLayout(11, 1));
        List<User> users = Application.getInstance().getUserManager().getTopScores();
        for (int i = 0; i < users.size(); i++) {
            StringBuilder builder = new StringBuilder();
            builder.append(i + 1);
            builder.append("     ");
            builder.append(users.get(i).getPlayerName());
            builder.append("     ");
            builder.append(users.get(i).getScore());
            builder.append("     ");
            builder.append(users.get(i).getLastPlayed());
            dialog.add(new JLabel(builder.toString()));
        }
        dialog.setSize((int) dialog.getPreferredSize().getWidth() * 2, (int) dialog.getPreferredSize().getHeight() * 2);
        dialog.setVisible(true);
        JButton okButton = new JButton("OK");
        okButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.dispose();
            }
        });
        dialog.add(okButton);

    }
}
